-module(device_interface).
-include("definitions.hrl").

-export([start/1]).

-spec start/1 :: (device()) -> no_return().
start(Descr) ->
  State = [],
  random:seed(erlang:now()),
  event_loop(Descr, State).

-spec event_loop/2 :: (device(), [message()]) -> ok.
event_loop(Descr, State) ->
  receive
    {message, Msg, From} ->
      timer:sleep(200),
%%       Rand = random:uniform(90),
%%       case Rand of
%%         1 ->
%%           From ! {answer, <<0:64>>};
%%         _ ->
%%           From ! {answer, Msg}
%%       end,
      From ! {answer, Msg},
      event_loop(Descr, [Msg | State]);
    stop -> ok
  end.
